package net.sareweb.acab.session;

import net.sareweb.acab.entity.*;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("travelHome")
public class TravelHome extends EntityHome<Travel> {

	@In(create = true)
	CityHome cityHome;
	@In(create = true)
	StateHome stateHome;
	@In(create = true)
	CountryHome countryHome;
	@In(create = true)
	UserHome userHome;

	public void setTravelIdTravel(Integer id) {
		setId(id);
	}

	public Integer getTravelIdTravel() {
		return (Integer) getId();
	}

	@Override
	protected Travel createInstance() {
		Travel travel = new Travel();
		return travel;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		City cityByToCity = cityHome.getDefinedInstance();
		if (cityByToCity != null) {
			getInstance().setCityByToCity(cityByToCity);
		}
		State stateByFromState = stateHome.getDefinedInstance();
		if (stateByFromState != null) {
			getInstance().setStateByFromState(stateByFromState);
		}
		Country countryByFromCountry = countryHome.getDefinedInstance();
		if (countryByFromCountry != null) {
			getInstance().setCountryByFromCountry(countryByFromCountry);
		}
		User user = userHome.getDefinedInstance();
		if (user != null) {
			getInstance().setUser(user);
		}
		State stateByToState = stateHome.getDefinedInstance();
		if (stateByToState != null) {
			getInstance().setStateByToState(stateByToState);
		}
		City cityByFromCity = cityHome.getDefinedInstance();
		if (cityByFromCity != null) {
			getInstance().setCityByFromCity(cityByFromCity);
		}
		Country countryByToCountry = countryHome.getDefinedInstance();
		if (countryByToCountry != null) {
			getInstance().setCountryByToCountry(countryByToCountry);
		}
	}

	public boolean isWired() {
		if (getInstance().getUser() == null)
			return false;
		return true;
	}

	public Travel getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List<Seat> getSeats() {
		return getInstance() == null ? null : new ArrayList<Seat>(getInstance()
				.getSeats());
	}

	public List<Match> getMatchs() {
		return getInstance() == null ? null : new ArrayList<Match>(
				getInstance().getMatchs());
	}

	public List<Dialog> getDialogs() {
		return getInstance() == null ? null : new ArrayList<Dialog>(
				getInstance().getDialogs());
	}

}
